<template>
  <!-- 处方弹窗 -->
  <div>
    <el-dialog
      v-model="props.visible"
      title="处方"
      top="10vh"
      width="1350px"
      append-to-body
      @close="$emit('close')"
    >
      <el-table
        ref="dataTableRef"
        v-loading="loading"
        :data="pageData"
        highlight-current-row
        border
      >
        <el-table-column key="name" label="名称" prop="name" min-width="150" align="center" />

        <el-table-column
          key="composition"
          label="组成"
          prop="composition"
          min-width="550"
          align="center"
        />

        <el-table-column
          key="addSubtract"
          label="加减"
          prop="addSubtract"
          min-width="550"
          align="center"
        />
        <el-table-column
          key="diseaseCn"
          label="中医病名"
          prop="diseaseCn"
          min-width="150"
          align="center"
        />
        <el-table-column
          key="disease"
          label="西医病名"
          prop="disease"
          min-width="150"
          align="center"
        />

        <el-table-column key="symptom" label="症状" prop="symptom" min-width="500" align="center" />
        <el-table-column
          key="syndrome"
          label="对证"
          prop="syndrome"
          min-width="500"
          align="center"
        />
        <el-table-column
          key="physiologica"
          label="药效"
          prop="physiologica"
          min-width="500"
          align="center"
        />
        <el-table-column
          key="etiolog"
          label="病因病机"
          prop="etiolog"
          min-width="500"
          align="center"
        />
      </el-table>

      <pagination
        v-if="total > 0"
        v-model:total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="handleQuery()"
      />

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="$emit('close')">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
/

<script setup lang="ts">
const props = defineProps({
  id: {
    type: Number,
    required: true,
  },
  visible: {
    type: Boolean,
    required: true,
  },
});

import TcmAPI, { TcmPageVO, TcmForm, TcmAriticlePageQuery } from "@/api/project/tcm";

const queryFormRef = ref(ElForm);
const dataFormRef = ref(ElForm);

const loading = ref(false);

const total = ref(0);

const queryParams = reactive<TcmAriticlePageQuery>({
  pageNum: 1,
  pageSize: 10,
  articleId: props.id,
});

// 中医处方表格数据
const pageData = ref<TcmPageVO[]>([]);

// 监听 visible 的变化
watch(
  () => props.visible,
  (newVal) => {
    if (newVal) {
      queryParams.articleId = props.id;
      handleQuery();
    }
  }
);

// 弹窗
const dialog = reactive({
  title: "",
  visible: false,
});

/** 查询中医处方 */
function handleQuery() {
  loading.value = true;
  TcmAPI.getAriclePage(queryParams)
    .then((data) => {
      pageData.value = data.list;
      total.value = data.total;
    })
    .finally(() => {
      loading.value = false;
    });
}

onMounted(() => {});
</script>
